grammar BasicArithmeticEqu;

options {
  language = Java;
  output = AST;
  ASTLabelType = CommonTree;
}

tokens{
  NEGATION;
}

@header {
  package calc;
}

@lexer::header {
  package calc;
}

problem
  :	operator EOF!
  ;

operator
	:	ADD
	| SUB
	|	MULT
	;

evaluator
  :  assignment* expression EOF!;
  
assignment
  : IDENT ':=' expression ';'
  ;

//expressions
term
  : IDENT
  |  '('! expression ')'!
  | INTEGER
  ;
  
/*negation : 'not'* term;*/

unary
  : ('+'! | negation^ )* term
  ;

negation
  :  '-' -> NEGATION
  ;

mult
  : unary (('*'^ | '/'^ | 'mod'^) unary)*
  ;

expression
  : mult (('+'^ | '-'^) mult)*;

fragment LETTER : ('a'..'z' | 'A'..'Z');
fragment DIGIT : '0'..'9';
INTEGER : DIGIT+;
IDENT  : LETTER (LETTER | DIGIT)*;
ADD	: '<add>';
SUB : '<sub>';
MULT	: '<mult>';
WS: (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;};
